package com.zhongxi.guoyuan.adapter.consume;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.consumerYield.ConsumeData;
import com.zhongxi.guoyuan.utils.CommonTool;
import com.zhongxi.guoyuan.utils.DataUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/13.
 */

public class ConsumeAdapter extends BaseAdapter {

    private Context context;
    private List<ConsumeData> list;
    private ConsumeData consumeData;

    public ConsumeAdapter(Context context) {
        this.context = context;
        this.list = new ArrayList<>();
    }

    public void setList(List<ConsumeData> list) {
        this.list = list;

        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.consume_item, parent, false);
            holder.tvTime= (TextView) convertView.findViewById(R.id.consume_item_time);
            holder.tvName= (TextView) convertView.findViewById(R.id.consume_item_name);
            holder.tvMoney= (TextView) convertView.findViewById(R.id.consume_item_price);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        if(null!=list.get(position)){
            consumeData = list.get(position);
           if (consumeData!=null){
                holder.tvTime.setText(CommonTool.formatDate(consumeData.getCtime()));
                holder.tvMoney.setText(DataUtil.formatDataSixPoint(consumeData.getSharesgains())+" 个");
                if (consumeData.getGainstype().equals("1")){
                    holder.tvName.setText("消费收益");


                    holder.tvName.setTextColor(context.getResources().getColor(R.color.bg_yield));
                    holder.tvMoney.setTextColor(context.getResources().getColor(R.color.bg_yield));
                }else if(consumeData.getGainstype().equals("2")){
                    holder.tvName.setText("分享奖励");


                    holder.tvName.setTextColor(context.getResources().getColor(R.color.title_red));
                    holder.tvMoney.setTextColor(context.getResources().getColor(R.color.title_red));
                }else if (consumeData.getGainstype().equals("3")){
                    holder.tvName.setText("消费多增");


                    holder.tvName.setTextColor(context.getResources().getColor(R.color.title_blue));
                    holder.tvMoney.setTextColor(context.getResources().getColor(R.color.title_blue));
                }

            }else {
                holder.tvTime.setText("");
                holder.tvName.setText("");
                holder.tvMoney.setText("");
            }
        }
        return convertView;
    }
    class ViewHolder{
        private TextView tvTime;
        private TextView tvMoney;
        private TextView tvName;
    }
}
